package com.jtjrenren.android.taxi.driver.core.main;


import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.jtjrenren.android.taxi.driver.base.MvpActivity;
import com.jtjrenren.android.taxi.driver.bean.DriverInfo;
import com.jtjrenren.android.taxi.driver.core.other.AppMoreActivity;
import com.jtjrenren.android.taxi.driver.manger.AppManger;
import com.jtjrenren.android.taxi.driver.utils.IntentUtils;
import com.jtjrenren.android.taxi.driver.utils.UIHelper;
import com.jtjrenren.android.taxi.driver.R;
import com.library.utils.StringUtils;
import com.library.weiget.CustomFiveStars;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/7/4.
 */
public class AppHomeActivity extends MvpActivity<MainPresenter> implements MainView {
    @BindView(R.id.ll_income_money)
    TextView tv_income;
    @BindView(R.id.main_driver_name)
    TextView tv_name;
    @BindView(R.id.main_driver_icon)
    ImageView iv_icon;
    @BindView(R.id.main_driver_level)
    CustomFiveStars rt_level;


    @Override
    public int getLayoutID() {
        return R.layout.aty_app_home;
    }

    @Override
    public void initM() {
        presenter.init();
        presenter.getSjSr();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.destory();
    }

    @OnClick(R.id.driver_exit)
    public void exitApp() {
        UIHelper.showDialog(this, null, null, "是否退出应用？", null, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppManger.getInstance().driverExit();
                finish();
                System.exit(0);
            }
        });
    }

    @OnClick(R.id.driver_sb)
    public void onDuty() {
        AppManger.getInstance().driverOnDuty();
        IntentUtils.goDutyOnActivity(this);
        finish();
    }

    @OnClick(R.id.ll_income)
    public void clickIncome() {
        IntentUtils.goWallectPage(this);
    }

    @OnClick(R.id.title_right)
    public void clickMore() {
        Intent intent = new Intent(this, AppMoreActivity.class);
        startActivity(intent);
    }

    @Override
    public MainPresenterImpl createPresenter() {
        return new MainPresenterImpl(this);
    }

    @Override
    public void finishAty() {
        finish();
    }


    @Override
    public void refreshDriverInfoView(DriverInfo info) {
        tv_name.setText(info.getName());
        ImageLoader.getInstance().displayImage(info.getHeadImg(), iv_icon, UIHelper.getDisplayOptions());
        rt_level.show(Integer.parseInt(StringUtils.isEmpty(info.getServiceLevel()) ?
                "5" : info.getServiceLevel()));
    }

    @Override
    public void refreshSr(String desc) {
        tv_income.setText(desc);
    }

    @Override
    public void showLoginView() {
        IntentUtils.goLoginPage(this);
        finish();
    }

}
